#include <math.h>
#include <string.h>
#include <iostream>

using std::cout;
using std::endl;

class Point {
public:
    Point ()
    :_x(0)
    ,_y(0) 
    {
        cout<<"Point(0,0)"<<endl;
    }

    Point(int x,int y)
    :_x(x)
    ,_y(y) 
    {
       cout<<"Point(int ,int)"<<endl; 
    }

    void showPoint(){
        cout<<"("<<_x<<","<<_y<<")";
    }

    int x()const{
        return _x;
    }
        
    int y()const{
        return _y;
    }
private:
    int _x;
    int _y;
};

class Line{
public:
    Line()
    :_p1(Point())
    ,_p2(Point()) 
    {
    cout<<"Line()"<<endl;
    }

    Line(int x1,int y1,int x2,int y2)
    :_p1(x1,y1)
    ,_p2(x2,y2) 
    {
    cout<<"Line(int,int,int,int)"<<endl;
    }

    const Point &p1()const{
        return _p1;
    }
    
    const Point &p2()const{
        return _p2;
    }

    void showLine(){
        cout<<"--------line_start---------------"<<endl;
        _p1.showPoint();
        cout<<"------------>";
        _p2.showPoint();
        cout<<endl;
        cout<<"--------lien_end---------------"<<endl;
    }


private:
    Point _p1;
    Point _p2;
};

class Color{
public:
    Color(const char*color)
    :_color(new char[strlen(color)+1])
    {
        strcpy(_color,color);
        cout<<"Color(const char*)"<<endl;
    }

    ~Color(){
        if(_color){
            cout<<"~Color"<<endl;
            delete []_color;
        }
    }

    const char *c_str(){
        return _color;
    }
        
private:
    char *_color;
};

//假设三角形为直角三角形
class Triangle:public Line,public Color
{
public:
    Triangle(int x1,int y1,int x2,int y2,const char *color,float heigh)
    :Line(x1,y1,x2,y2)
    ,Color(color)
    ,_heigh(heigh) 
    {
        cout<<"Triangle(int,int,int,int,const char*,float)"<<endl;
    }

    //TODO:获取p1和p2之间的距离
    float getPerimeter(){
    const Point &p1 = Line::p1();
    const Point &p2 = Line::p2();
    float dx = p1.x() - p2.x();
    float dy = p1.y() - p2.y();
    float line = sqrt(dx*dx + dy*dy);
    
    return line+_heigh+sqrt(line*line+_heigh*_heigh);
    }

    float getArea(){
    const Point &p1 = Line::p1();
    const Point &p2 = Line::p2();
    float dx = p1.x() - p2.x();
    float dy = p1.y() - p2.y();
    float line = sqrt(dx*dx + dy*dy);

    return 0.5*_heigh*line;
    }

    void showTriangle()
    {
        cout<<"---------Triangle_info------------"<<endl;
        cout<<"Triangle's color: "<<Color::c_str()<<endl;
        cout<<"Triangle's Perimeteri: "<<getPerimeter()<<endl;
        cout<<"Triangle's getArea: "<<getArea()<<endl;
        cout<<"--------------------"<<endl;
    }


private:
    float _heigh;
};


void test(){
    Triangle t1(0,0,3,0,"red",4.0);
    t1.showTriangle();
}

int main()
{
    test ();
    return 0;
}

